<template>
	<view>
		
		<z-paging ref="paging"  v-model="dataList" @query="queryList">
			
			<u-navbar slot="top" :fixed="false" back-text="" :leftIconColor="tksetting.titlecolor" :bgColor="tksetting.color" :titleStyle="{color:tksetting.titlecolor}" title="问卷调查"  :autoBack="true"  :placeholder="true">
			</u-navbar>
			
		<view class="body">			
			<u-cell-group>
			
					<u-cell
						v-for="(item,index) in dataList" :key="index"
						@click="itemClick(item.id,item.is_finsh)"
						:isLink="item.is_finsh?false:true"
						arrow-direction="right"
					>
					<u--text slot="title" :text="item.title"></u--text>
					<view v-show="item.is_finsh" slot="value" >
						<u-badge value="已完成" type="success"></u-badge>
					</view>
					<view slot="label" >
						<u--text type="info" size="12"  :text="`开始:`+item.st"></u--text>
						<u--text type="info" size="12"  :text="`结束:`+item.et"></u--text>
						<view v-if="item.jf>0" style="display: flex;">
							<u-badge :value="`奖励积分:`+item.jf" type="success"></u-badge>
						</view>
					</view>
					<u--image 
					:src="item.img" 
					slot="icon"
					mode="scaleToFill"
					width="80"
					height="80"
					radius="12"
					>
					</u--image>
				</u-cell>
			</u-cell-group>
			
		</view>
		</z-paging>	
	</view>

</template>

<script>
	import {toast,showModal,isImageUrlByExtension, clearStorageSync, setStorageSync, getStorageSync, useRouter} from '@/utils/utils.js'
	import { mapState } from 'vuex';
export default {
	
	data() {
		return {
			dataList:[
				{
					id:'',
					title:'',
					st:'',
					et:'',
					img:'',
					jf:''
				}
			]
		};
	},
	onLoad() {
		uni.$on('updateValueInDataArr',this.relod_data)
	},
	onUnload() {
		//监听配对使用
		uni.$off('updateValueInDataArr');
	},
	onShow() {
			
	},
	computed: {
		...mapState(['tksetting']),
	},
	methods:{
		relod_data(){
			this.$refs.paging.reload(true)
		},
		itemClick(id,is_finsh) {
			const params = {
				id: id
			}
			
			if(is_finsh){
				toast('您已完成调查')
			}else{
				useRouter('/pages/tiku/wenjuan2',params,'navigateTo')
			}
			
		},
		queryList(pageNo, pageSize) {
			const params = {
				page: pageNo,
				limit: pageSize,
			}
			
			this.$api.wenjuan_list(params).then(res => {
				console.log(res);
				if (res.code == 0) {
					this.$refs.paging.complete(res.data);
				}else{
					this.$refs.paging.complete(false);
				}
			}).catch(res => {
		        	// 如果请求失败写this.$refs.paging.complete(false)，会自动展示错误页面
		        	// 注意，每次都需要在catch中写这句话很麻烦，z-paging提供了方案可以全局统一处理
		        	// 在底层的网络请求抛出异常时，写uni.$emit('z-paging-error-emit');即可
		        	this.$refs.paging.complete(false);
		        })
		
		}
	}
};
</script>

<style scoped lang="scss">
	.body{
		padding: 0rpx;
	}
	
	
</style>